package api

import (
	"GopherFocus/app/model"
	"GopherFocus/app/system/index/internal/define"
	"GopherFocus/app/system/index/internal/service"
	"github.com/gogf/gf/net/ghttp"
)

var Search = searchApi{}

type searchApi struct{}

func (a *searchApi) Index(r *ghttp.Request) {
	var (
		req *define.ContentSearchReq
	)
	if err := r.Parse(&req); err != nil {
		service.View.Render500(r, model.View{
			Error: err.Error(),
		})
	}
	if searchRes, err := service.Content.Search(r.Context(), req.ContentSearchInput); err != nil {
		service.View.Render500(r, model.View{
			Error: err.Error(),
		})
	} else {
		service.View.Render(r, model.View{
			// 为什么这里的GetTitle啥也不传？？是因为只显示首页吗，不需要面包屑导航？？
			Title: service.View.GetTitle(r.Context(), &define.ViewGetTitleInput{}),
			Data:  searchRes,
		})
	}
}
